Page({
  data: {
    userInfo: {}, // 用户信息对象
    orderItems: [{
        icon: '/image/mine/icon/待支付.png',
        text: '待支付'
      },
      {
        icon: '/image/mine/icon/待发货.png',
        text: '待发货'
      },
      {
        icon: '/image/mine/icon/待收货.png',
        text: '已完成'
      },
      {
        icon: '/image/mine/icon/待评价.png',
        text: '已评价'
      },
      {
        icon: '/image/mine/icon/售后.png',
        text: '售后中'
      }
    ],
    multipurposeItems: [{
        icon: '/image/mine/icon/收藏.png',
        text: '我的积分'
      },
      {
        icon: '/image/mine/icon/会员.png',
        text: '我的会员'
      },
      {
        icon: '/image/mine/icon/我的地址.png',
        text: '收货地址'
      },
      {
        icon: '/image/mine/icon/客服中心.png',
        text: '客服中心'
      }
    ]
  },

  onLoad() {
    this.updateUserInfo();
  },

  onShow() {
    this.updateUserInfo();
  },

  // 从本地存储中获取用户信息并更新页面
  updateUserInfo() {
    const userInfo = wx.getStorageSync('userInfo') || {};
    this.setData({
      userInfo
    });
  },

  // 编辑个人信息
  editProfile() {
    wx.navigateTo({
      url: '/pages/profile/profile'
    });
  },

  // 跳转到收货地址页面
  navigateToAddress() {
    wx.navigateTo({
      url: '/pages/address/address'
    });
  },

  // 跳转到我的订单页面并携带状态参数
  navigateToMyOrdersWithStatus(e) {
    const status = e.currentTarget.dataset.status;
    wx.navigateTo({
      url: `/pages/MyOrders/MyOrders?orderStatusFilter=${encodeURIComponent(status)}`
    });
  },

  // 跳转到我的订单页面
  navigateToMyOrders() {
    wx.navigateTo({
      url: '/pages/MyOrders/MyOrders'
    });
  },

  // 跳转到我的积分页面
  navigateToMyPoints() {
    wx.navigateTo({
      url: '/pages/MyPoints/MyPoints'
    });
  },

  // 跳转到我的会员页面
  navigateToMyMember() {
    wx.navigateTo({
      url: '/pages/MyMember/MyMember'
    });
  },

  // 退出登录
  logout() {
    // 清除本地存储中的用户信息
    wx.removeStorageSync('userInfo');
    wx.removeStorageSync('isLogin');

    // 提示用户退出成功
    wx.showToast({
      title: '退出成功',
      icon: 'success',
      duration: 2000,
      success: () => {
        // 确保提示框显示后立即跳转到登录页面
        setTimeout(() => {
          wx.redirectTo({
            url: '../login/login'
          });
        }, 2000);
      }
    });
  }
});